import 'package:sow_app_core/sow_app_core.dart';
import 'package:sow_app_i18n/sow_app_i18n.dart';
import 'package:test/test.dart';

import 'package:sow_app_mock/sow_app_mock.dart';

void main() {
  group('app controller test group', () {
    final MockAppPresenter presenter = MockAppPresenter();
    final RestClient restClient = MockRestClient();
    final CacheRepository cache = MockCacheRepository();
    final controller = MockAppController(presenter, restClient);
    test(
      "should present valid current and currentToken when invoke init",
      () async {
        // arrange
        cache.set(I18n.ajax_info, "a,66,c,d");
        // act
        controller.init();
        await Future.doWhile(() => presenter.flag = false);
        // assert
        expect(controller.appPresenter.current, 1);
        expect(controller.appPresenter.currentToken, isEmpty);
      },
    );
    test(
      "should present valid current and currentTok when invoke pageChange",
      () async {
        // arrange
        // act
        controller.pageChange(2);
        // assert
        await Future.doWhile(() => presenter.flag = false);
        expect(controller.appPresenter.current, 2);
        expect(controller.appPresenter.currentToken, isNotEmpty);
      },
    );
  });
}
